// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: perf proc tools
 * Author: Huawei Technologies Co., Ltd
 * Create: 2022-04-28
 */
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include "./perf-tools.h"

static int __init perf_proc_tools_init(void)
{
	int ret;
	struct proc_dir_entry *perf_dir;
	perf_dir = proc_mkdir(PROC_PERF_TOOLS_DIR_NAME, NULL);
	if (!perf_dir) {
		pr_err("[perf_proc_tools] [error]: create /proc/perf failed\n");
		return -EINVAL;
	}

	ret = init_perf_sched(perf_dir);
	if (ret != 0) {
		pr_err("[perf_proc_tools] [error]: init perf sched failed\n");
		goto remove_proc;
	}
	return 0;
remove_proc:
	remove_proc_subtree(PROC_PERF_TOOLS_DIR_NAME, NULL);
	return ret;
}

static void __exit perf_proc_exit(void)
{
	exit_perf_sched();
	remove_proc_subtree(PROC_PERF_TOOLS_DIR_NAME, NULL);
}
module_init(perf_proc_tools_init);
module_exit(perf_proc_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Perf Proc Tools Driver");
MODULE_AUTHOR("HUAWEI TECHNOLOGIES CO., LTD.");
MODULE_VERSION("V1.0");
